//接口地址格式化地址
function formatUrl(url) {
  return BASE_URL + url + SUFFIX;
}

//图片引用地址
function pathUrl(url) {
  return PATH + url;
}

//滚动设置
function wresize(callback) {
  $(window).unbind()
  $(window).resize(callback);
  $(window).resize();
}

//获取当前body高度
function getBodyHeight(minus) {
  minus = parseInt(minus);
  if (empty(minus))
    return document.body.offsetHeight;
  else
    return document.body.offsetHeight - minus;
}

function getBodyWidth(minus) {
  minus = parseInt(minus);
  if (empty(minus))
    return document.body.offsetWidth;
  else
    return document.body.offsetWidth - minus;
}

//判断是否为空
function empty(vars) {
  var result = false;
  if (vars) {
    if (typeof(vars) == 'object') {
      if (vars instanceof Object && Object.keys(vars).length == 0) {
        result = true;
      } else if (vars instanceof Array && vars.length == 0) {
        result = true;
      }
    }
  } else {
    result = true;
  }
  return result;
}

//数组中是否存在数据
function in_array(search, arr) {
  for (var i in arr) {
    if (arr[i] == search) {
      return true;
    }
  }
  return false;
}
//去除数组中的重复数据
function unique_array(arr) {
  var tmp = new Array();
  for (var i = 0; i < arr.length; i++) {
    //该元素在tmp内部不存在才允许追加
    if (tmp.indexOf(arr[i]) == -1) {
      tmp.push(arr[i]);
    }
  }
  return tmp;
}
//字符串转json格式
function str2json(str) {
  var json = eval('(' + str + ')');
  return json;
}

//字符串转数组格式
function str2arr(str) {
  var json = Array();
  var arr = str.split(";");
  arr.map(function(item) {
    json.push(item.split(","));
  });
  return json
}

//格式化数字，保留小数
function formatNumber(val, fixed) {
  fixed = fixed ? fixed : 2;
  return parseFloat(val).toFixed(fixed);
}

//格式化时间戳
function formatDate(time, format) {
  var newDate = new Date();
  time ? newDate.setTime(time) : '';
  format = format ? format : 'yyyy-MM-dd hh:mm:ss';
  var date = {
    "M+": newDate.getMonth() + 1,
    "d+": newDate.getDate(),
    "h+": newDate.getHours(),
    "m+": newDate.getMinutes(),
    "s+": newDate.getSeconds(),
    "q+": Math.floor((newDate.getMonth() + 3) / 3),
    "S+": newDate.getMilliseconds()
  };
  if (/(y+)/i.test(format)) {
    format = format.replace(RegExp.$1, (newDate.getFullYear() + '').substr(4 - RegExp.$1.length));
  }
  for (var k in date) {
    if (new RegExp("(" + k + ")").test(format)) {
      format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
    }
  }
  return format;
}

//格式化时间戳
function dateTime(format) {
  var date = new Date(Date.parse(format.replace(/-/g, "/")));
  return date.getTime();
}

function getArgs(key) {
  var l = window.location.hash;
  if (l.indexOf('?') == -1) return '';
  l = l.split('?')[1];
  ary = l.split("&");
  for (var i = 0; i < ary.length; i++) {
    if (ary[i].split("=")[0] == key) {
      return ary[i].split("=")[1];
    }
  }
  return '';
}

function getParam(param) {
  param.tenantId = getArgs('tenantId') || '8d86bfc4e8e64fb088b93fc9ca3d6525',
    param.userId = getArgs('userId') || '4e9e45df34c04dcd837bd8b2930a6411'
  return param;
}

function getParameters(param) {
  var parameters = {
    authParam: {
      tenantId: getArgs('tenantId') || '8d86bfc4e8e64fb088b93fc9ca3d6525',
      userId: getArgs('userId') || '4e9e45df34c04dcd837bd8b2930a6411'
    },
    param: param,
    reqMethod: {
      isJsonP: 1
    }
  };
  parameters.param.userId = getArgs('userId') || '4e9e45df34c04dcd837bd8b2930a6411';
  return { parameters: JSON.stringify(parameters) }
}

